<?php

namespace app\api\controller\tieba;

use app\api\service\tieba\OperationService;
use think\Request;

class Operation
{
    protected $Service;
    public function __construct()
    {
        $this->Service = OperationService::getInstance();
    }

    /**
     * @auth('链接列表','贴吧管理')
     * @param Request $request
     * @param('page','页数','require')
     * @return \think\response\Json
     */
    public function tiebaList(Request $request){
        $params  = $request->get();
        $result = $this->Service->getTiebaList($params);
        return writeJson(201, $result, '视频列表');
    }

    /**
     * @auth('是否表格导入','贴吧管理')
     * @param Request $request
     * @return \think\response\Json
     */
    public function tiebaImport(Request $request){
        $params  = $request->post();
        $result = $this->Service->tiebaImport($params);
        return writeJson(201, $result, '导入成功');


    }

    public function getTiebaDetail(){
        $params = \think\facade\Request::get();

        $url = "http://127.0.0.1:5000/baijiahao/tieba/detail?url=".$params['url'];

        $result = curlGet($url);

        $result = json_decode($result,true)['result'];

        return writeJson(200,$result,'成功！');
    }

    public function tiebaUpload(Request $request){
        $params  = $request->post();
        $this->Service->tiebaUpload($params);
        return writeJson(201,'','上传成功');
    }

    public function distribute(Request $request){
        $params = $request->get();
        $result = $this->Service->distribute($params);
        return writeJson(201,$result,'数据列表！');

    }

    public function write(Request $request){
        $params = $request->post();
        $result = $this->Service->write($params);
        return writeJson(200,$result,'发布完成！');
    }

    public function textRewriting(Request $request){
        $params = $request->post();
        $result = $this->Service->rewriting($params);
        return writeJson(201,$result,"重写成功");
    }

}
